<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>管理员列表</title>
    <link rel="stylesheet" type="text/css" href="/static/h+/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="/static/h+/css/font-awesome.min93e3.css?v=4.4.0">
    <!-- Data Tables -->
    <link rel="stylesheet" type="text/css" href="/static/h+/css/plugins/dataTables/dataTables.bootstrap.css">
    <link rel="stylesheet" type="text/css" href="/static/h+/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="/static/h+/css/style.min.css?v=4.1.0">
    <link rel="stylesheet" type="text/css" href="/static/layer/skin/layer.css">
    <link rel="stylesheet" type="text/css" href="/static/paging/paging.css">
    <style type="text/css">
        .form-control{width: 220px;}
        .ttd{width: 250px;text-align: center;}
        .ttb{width: 80px;text-align: center;}
        .avatar{width: 64px;height: 64px;border-radius: 32px;}
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
  <div class="row">
    <div class="col-sm-12">
      <div class="ibox float-e-margins">
        <div class="ibox-title">
          <form action="{:url('lists')}" method="get">
            <table cellpadding="0" cellspacing="0" width="100%" border="0">
              <tr>
                <td class="ttd"><input type="text" name="keyword" placeholder="账号" class="input-sm form-control" value="{$param.keyword}"></td>
                <td class="ttd">
                  <select class="form-control" name="type">
                    <option value="0">…用户角色…</option>
                    {foreach $roles as $r}
                    <option value="{$r.id}"{if(intval($param.type)===$r.id)} selected="1"{/if}>{$r.role_name}</option>
                    {/foreach}
                  </select>
                </td>
                <td class="ttd">
                  <select class="form-control" name="status">
                    <option value="0">…用户状态…</option>
                    {foreach $status as $s}
                    <option value="{$s.id}" {if(intval($param.status)===$s.id)} selected="1"{/if}>{$s.name}</option>
                    {/foreach}
                  </select>
                </td>
                <td class="ttb"><input type="submit" class="btn btn-sm btn-primary" value="搜索"></td>
                <td>
                  <a href="{:url('add')}">添加</a> | {if($is_ip===1)}<a href="javascript:;" data-action="mipAll">批量免IP</a> | <a href="javascript:;" data-action="nipAll">批量限制IP</a> | {/if}<a href="javascript:;" data-action="enableAll">批量启用</a> | <a href="javascript:;" data-action="disableAll">批量禁用</a> | <a href="javascript:;" data-action="delAll">批量删除</a>
                </td>
                <td>&nbsp;</td>
              </tr>
            </table>
          </form>
        </div>
        <div class="ibox-content">
          <table class="table table-striped table-bordered table-hover dataTables-example">
            <thead>
            <tr>
              <th><input type="checkbox" id="selAll"></th>
              <th>序号</th>
              <th>账号</th>
              {if($is_ip===1)}
              <th>是否限制IP</th>
              {/if}
              <th>登录时间</th>
              <th>添加时间</th>
              <th>状态</th>
              <th style="width: 200px;">操作</th>
            </tr>
            </thead>
            <tbody>
              {foreach $list as $k=>$item}
              <tr class="gradeX">
                <td>{if($item.username!='admin')}<input type="checkbox" class="check" value="{$item.id}">{/if}</td>
                <td>{$k+1}</td>
                <td>{$item.username}</td>
                {if($is_ip===1)}
                <td>{$item.is_ip_txt}</td>
                {/if}
                <td>{$item.login_time}</td>
                <td>{$item.ctime}</td>
                <td>{$item.status_txt}</td>
                <td>{if($item.username!='admin')}<a href="{:url('edit')}?id={$item.id}">编辑</a> | {if($item.status===1)}<a href="javascript:;" data-action="disable" data-id="{$item.id}">禁用</a>{elseif($item.status===4)}<a href="javascript:;" data-action="enable" data-id="{$item.id}">启用</a>{/if} | <a href="javascript:;" data-action="del" data-id="{$item.id}">删除</a>{/if}</td>
              </tr>
              {/foreach}
              </tbody>
            <footer>
              <tr>
                <td colspan="100"><div class="dataTables_paginate paging_simple_numbers paging_page">{$pages}</div></td>
              </tr>
            </footer>
          </table>
        </div>
      </div>
    </div>
  </div>
</div>
</body>
<script type="text/javascript" src="/static/h+/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/layer/layer.js"></script>
<script type="text/javascript" src="/static/paging/paging-min.js"></script>
<script>
    $(function () {
        $('.gradeX').each(function(){
            $(this).children('td:eq(0)').siblings().click(function(){
                var chk = $(this).parent('tr').find('.check');
                chk.click()
            })
        });
        $('#selAll').click(function(){
            if ($(this).is(':checked')) {
                $('.check').prop('checked', true);
            }else{
                $('.check').prop('checked', false);
            }
        });
        $('a[data-action]').click(function(){
            var $action = $(this).data('action'), $id = $(this).data('id');
            var $ids = '0', $type = '';
            if($action == 'del' || $action == 'disable' || $action == 'enable' || $action == 'mip' || $action == 'nip'){
                $ids = '0,' + $id;
            } else if ($action == 'delAll' || $action == 'disableAll' || $action == 'enableAll' || $action == 'mipAll' || $action == 'nipAll') {
                $('.check').each(function(){
                    if ($(this).is(':checked')) {
                        $ids += (',' + $(this).val())
                    }
                });
            }
            operate($ids, $action)
        });

        function operate($ids, $type) {
            var $msg = '', $tip = '';
            if ($type == 'del' || $type == 'delAll') {
                $msg = '确实要删除吗？';
                $tip = '删除'
            } else if ($type == 'disable' || $type == 'disableAll') {
                $msg = '确实要禁用吗？';
                $tip = '禁用'
            } else if ($type == 'enable' || $type == 'enableAll') {
                $msg = '确实要启用吗？';
                $tip = '启用'
            } else if ($type == 'mip' || $type == 'mipAll') {
                $msg = '确实要免IP吗？'
                $tip = '免IP';
            } else if ($type == 'nip' || $type == 'nipAll') {
                $msg = '确实要限制IP吗？';
                $tip = '限制IP';
            }
            if ($ids == '0') {
                layer.msg('请选择要' + $tip + '的项');
                return false
            }
            layer.confirm($msg, {icon: 3}, function(){
                $.ajax({
                    type: 'post', cache: false, dataType: 'json',
                    url: '{:url("operate")}',
                    data:{'ids': $ids, 'type': $type},
                    success: function(data){
                        if (data.status == 0) {
                            layer.msg(data.info, {icon: 1, time: 1000}, function(){
                                location.reload();
                            });
                        }else{
                            layer.msg(data.info, {icon: 5})
                        }
                    }
                })
            })
        }
    });
</script>
</html>
